//
// Created on 2025/7/19.
//
// Node APIs are not fully supported. To solve the compilation error of the interface cannot be found,
// please include "napi/native_api.h".

#ifndef STREAMCORE_ARRAY_H
#define STREAMCORE_ARRAY_H
#include <napi/native_api.h>
class NapiArray {
public:
    NapiArray(napi_env env, napi_value value) : env_(env), value_(value) {
        napi_get_array_length(env, value, &length_);
    }

    size_t size() const { return length_; }

    template <typename T> T get(size_t index) {
        napi_value value;
        napi_get_element(env_, value_, index, &value);
        return As<T>(env_, value);
    }

    template <typename T> void set(size_t index, const T &value) {
        napi_set_element(env_, value_, index, From<T>(env_, value));
    }

private:
    napi_env env_;
    napi_value value_;
    uint32_t length_ = 0;
};

#endif // STREAMCORE_ARRAY_H
